﻿using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Menu;
using B.S.BasicData.Read.DTOS;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Menu
{
    public class MenuNameCommandHandle:IRequestHandler<MenuNameCommand,ApiResult<List<MenuDto>>>
    {
        private readonly IBaseRepository<MenuModel> MeunDal;

        public MenuNameCommandHandle(IBaseRepository<MenuModel> meunDal)
        {
            MeunDal = meunDal;
        }

        public Task<ApiResult<List<MenuDto>>> Handle(MenuNameCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MenuDto>> result = new ApiResult<List<MenuDto>>();
            var info = MeunDal.GetAll().Where(x=>x.IsDeleted == false).Select(x=> new MenuDto() {
                MenuId = x.MenuId,
                MenuName = x.MenuName,
            }).ToList();
            result.Code = ApiEnum.Success;
            result.Message = "菜单查询成功";
            result.Data = info;
            return Task.FromResult(result);
        }


    }
}
